import java.util.TreeSet;


/**
 * @author Edgard
 * @since 02/11/2011
 */
public class Route implements Comparable<Route>{
	Tile start, end;
	double distance=0;
	/**
	 * @author edgardleal
	 * @since 02/11/2011
	 */
	public Route(Tile start, Tile end,double distance) {
		this.start = start;
		this.end = end;
		this.distance = distance;
	}
	
	public Aim getDirection(Ants ants){
		Node grafo = ants.getGrafo(start, end);
		Aim direction;
		TreeSet<Node> trajectory = new TreeSet<Node>();
		if(grafo.find(end, trajectory)!=null){
			direction = ants.getDirections(start, trajectory.iterator().next().value).get(0);
			trajectory = null;
			grafo = null;
			return direction;
		}
		return Aim.EAST;
	}

	public void setStart(Tile start){
		this.start = start;
	}

	public double getDistance(){
		return distance;
	}
	
	public double getDistance(Tile start){
		return Vector.getDistance(start.getCol(), start.getRow(), end.getCol(), end.getRow());
	}
	
	public Tile getTarget(){
		return end;
	}

	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Route o) {
		int result = this.getDistance()> o.getDistance()?1:(this.getDistance()<o.getDistance()?-1:0);
		return result;
	}
	
	@Override
	public boolean equals(Object obj){
		if(obj instanceof Route){
			return start.equals(((Route)obj).start) && end.equals(((Route)obj).end);
		}else
			return false;
	}
	@Override
    public int hashCode() {
        return start.hashCode() * Ants.MAX_MAP_SIZE * Ants.MAX_MAP_SIZE + end.hashCode();
    }
}
